/**
 * All Rights Reserved , Copyright (C) 2020 , 青岛鼎信通讯股份有限公司
 * <p>
 * BaseChangeLogController
 * 变更记录表
 * <p>
 * 修改纪录
 * 2020-12-01 版本：1.0 zhanglongfei 创建。
 *
 * @version 版本：1.0
 * @author 作者：zhanglongfei
 * 创建日期：2020-12-01
 */

package com.topscomm.base.controller;

import com.topscomm.base.controller.auto.BaseChangeLogControllerAuto;
import com.topscomm.base.pojo.BaseChangeLogEntity;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author: zhanglongfei
 * @date: 2020-12-01
 * @description:变更记录表Controller
 * @modify:
 */
@RestController
@RequestMapping("base/changeLog")
public class BaseChangeLogController extends BaseChangeLogControllerAuto implements IBaseChangeLogController {
    /**
     * @author: zhanglongfei
     * @date: 2020-12-01
     * @param paraMap
     * @return
     * @description:转换出查询SQL语句
     * @modify:
     */
    @Override
    protected String spellListSql(Map<String, Object> paraMap) {
        StringBufferProxy sql = new StringBufferProxy();
        sql.appendSingle(" 1=1 ");
        if (paraMap.containsKey("qry_name")) {
            String value = paraMap.get("qry_name").toString();
            if (!StringUtil.isEmpty(value))
                sql.appendSingle(" and name like '%{0}%' ", value);
        }
        if (paraMap.containsKey("qry_code")) {
            String value = paraMap.get("qry_code").toString();
            if (!StringUtil.isEmpty(value))
                sql.appendSingle(" and code = '{0}' ", value);
        }
        return sql.toString();
    }

    /**
     * @author: zhanglongfei
     * @date: 2020-12-01
     * @param paraMap
     * @return
     * @description:转换出查询SQL语句
     * @modify:
     */
    @Override
    @GetMapping(value = "/refList")
    public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
        return super.refList(paraMap);
    }

    /**
     * @description: 添加客户变更记录
     * @param paraMap
     * @return com.topscomm.pub.vo.ResponseResult<java.lang.Object>
     * @author: wangxinhua
     * @date: 2020/12/1 18:31
     * @modify:
     */
    @PostMapping(value = "insertChangeLog")
    public ResponseResult<Object> insertChangeLog(@RequestBody(required = false) Map<String, Object> paraMap) {
        try {
            String insertRes = this.service.insertChangeLog(paraMap);
            return ResponseResult.ok("成功!");
        } catch (Exception e) {
            return handleControllerException(e);
        }
    }

    /**
     * @Description: 根据入参查询不同客户表的历史记录, 更具创建时间倒叙排序
     * @Author: mengmeng
     * @Param: paraMap{
     *     sourceType:
     *     sourceId:
     *     topSourceType:
     *     topSourceId
     * }
     * @Return: List<BaseChangeLogEntity>
     * @Date: 2020/12/8 19:31
     */
    @GetMapping(value = "/queryChangeHistoryLog")
    public ResponseResult<Object> queryChangeHistoryLog(@RequestParam(required = false) Map<String, Object> paraMap) {
        try {
            List<Map<String, Object>> maps = this.service.queryChangeLogByOptions(paraMap);
            return ResponseResult.ok("成功!", maps);
        } catch (Exception e) {
            return handleControllerException(e);
        }
    }
}

